using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.Page
{
	public class VerifiedPeopleInfo : BasePage
	{
		private const string TAG = "VerifiedPeopleInfo";
		private string mStrUserName;
		public Contact mContact;
		private bool mBIsFirstLoaded = true;
		private EventWatcher mWatchAddContact;
		private object mObjectWatcher = new object();
		private bool mBIsTogglesInited;
		private ProfileClickContentGridCtrl ctrlTWeibo;
		private ApplicationBar mBar;
		internal Grid LayoutRoot;
		internal ScrollViewer svRoot;
		internal StackPanel panelProfile;
		internal StackPanel panelTop;
		internal BrandHeadCtrl imgHead;
		internal ScrollTextBlock txtNicks;
		internal TextBlock txtID;
		internal Image imgVerifyTag;
		internal TextBlock txtVerifyTag;
		internal EmojiTextEx txtSig;
		internal StackPanel panelContentInfo;
		internal Grid panelAblum;
		internal ProfileTxtContentCtrl ctrlVerify;
		internal Button btnFollow;
		internal StackPanel panelFollowed;
		internal BrandCustomLinksCtrl ctrlBrandLinks;
		internal MMToggleSwitch toggleReceive;
		internal MMToggleSwitch toggleShowInMyList;
		internal Button btnSeeMsg;
		private bool _contentLoaded;
		public VerifiedPeopleInfo()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.Page_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Page_Unloaded));
		}
		private void Page_Loaded(object sender, RoutedEventArgs e)
		{
			if (this.mBIsFirstLoaded)
			{
				this.mBIsFirstLoaded = false;
				ContactMgr.tryRefreshContact(this.mContact);
			}
			Log.smethod_5("VerifiedPeopleInfo", "Page_Loaded");
		}
		private void Page_Unloaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("VerifiedPeopleInfo", "Page_Unloaded");
		}
		protected override void OnPageIn(object[] object_0)
		{
			Log.smethod_5("VerifiedPeopleInfo", "OnPageIn");
			if (object_0 != null && object_0.Length != 0)
			{
				if (object_0[0].GetType() == typeof(Contact))
				{
					Contact contact = object_0[0] as Contact;
					Contact contact2 = StorageMgr.contact.method_0(contact.strUsrName);
					this.registerEvent();
					if (contact2 == null)
					{
						this.getCover(strings.COM_Loading);
						this.mContact = contact;
						NetSceneBatchGetContact arg_7D_0 = ServiceCenter.sceneBatchGetContact;
						List<string> list = new List<string>();
						list.Add(contact.strUsrName);
						arg_7D_0.doScene(list);
						this.registerGetContactEvent();
						return;
					}
					this.mContact = contact2;
					this.initUI();
					return;
				}
			}
			base.GoBack();
		}
		protected override void OnPageOut()
		{
			Log.smethod_5("VerifiedPeopleInfo", "OnPageOut");
			this.unRegisterEvent();
		}
		protected override void OnPageBack()
		{
			Log.smethod_5("VerifiedPeopleInfo", "OnPageBack");
		}
		private void registerEvent()
		{
			if (this.mWatchAddContact == null)
			{
				this.mWatchAddContact = new EventWatcher(this.mObjectWatcher, null, new EventHandlerDelegate(this.OnAddContact));
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_ADDCONTACT_SUCCESS, this.mWatchAddContact);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_ADDCONTACT_ERR, this.mWatchAddContact);
			}
		}
		private void registerGetContactEvent()
		{
			if (this.mWatchAddContact != null)
			{
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_BATCH_GET_CONTACT_ERR, this.mWatchAddContact);
				EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchAddContact);
			}
		}
		private void unRegisterGetContactEvent()
		{
			if (this.mWatchAddContact != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_BATCH_GET_CONTACT_ERR, this.mWatchAddContact);
				EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchAddContact);
			}
		}
		private void unRegisterEvent()
		{
			if (this.mWatchAddContact != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_ADDCONTACT_SUCCESS, this.mWatchAddContact);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_ADDCONTACT_ERR, this.mWatchAddContact);
				this.unRegisterGetContactEvent();
				this.mWatchAddContact = null;
			}
		}
		private void OnAddContact(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
			string text = "";
			if (evtArgs.mObject != null && evtArgs.mObject is AddContactEventArgs)
			{
				AddContactEventArgs addContactEventArgs = evtArgs.mObject as AddContactEventArgs;
				text = addContactEventArgs.toUserName;
			}
			EventConst mEventID = evtArgs.mEventID;
			switch (mEventID)
			{
			case EventConst.ON_NETSCENE_ADDCONTACT_ERR:
				if (text != this.mContact.strUsrName)
				{
					return;
				}
				this.releaseCover();
				MMMessageBox.Show(strings.Web_Add_Contact_AddFail, true, "确定");
				this.refreshFllowedStatus();
				return;
			case EventConst.ON_NETSCENE_ADDCONTACT_SUCCESS:
				if (text != this.mContact.strUsrName)
				{
					return;
				}
				if (evtArgs.mObject != null && evtArgs.mObject is AddContactEventArgs)
				{
					this.releaseCover();
					ContactMgr.operationSetContact(this.mContact, true);
					this.refreshFllowedStatus();
					return;
				}
				break;
			default:
				if (mEventID != EventConst.ON_NETSCENE_BATCH_GET_CONTACT_ERR)
				{
					if (mEventID != EventConst.ON_STORAGE_CONTACT_ADD)
					{
						return;
					}
					if (evtArgs.mObject != null && evtArgs.mObject is List<object> && this.mContact != null)
					{
						List<Contact> listObject = evtArgs.getListObject<Contact>();
						if (listObject == null)
						{
							return;
						}
						using (List<Contact>.Enumerator enumerator = listObject.GetEnumerator())
						{
							while (enumerator.MoveNext())
							{
								Contact current = enumerator.get_Current();
								if (current != null && current.strUsrName == this.mContact.strUsrName)
								{
									this.mContact = current;
									this.releaseCover();
									this.initUI();
									this.unRegisterGetContactEvent();
									break;
								}
							}
							break;
						}
					}
					return;
				}
				else
				{
					this.releaseCover();
					this.unRegisterGetContactEvent();
					this.initUI();
				}
				break;
			}
		}
		private object imgHead_mDlgHeadClicked(object sender, object object_0)
		{
			if (sender == null)
			{
				return null;
			}
			if (!(sender is UIElement))
			{
				return null;
			}
			Point point = default(Point);
			object result;
			try
			{
				GeneralTransform generalTransform = this.imgHead.TransformToVisual(Application.get_Current().get_RootVisual());
				point = generalTransform.Transform(new Point(0.0, 0.0));
				goto IL_5B;
			}
			catch
			{
				result = null;
			}
			return result;
			IL_5B:
			Rect rect = new Rect(point.get_X(), point.get_Y(), this.imgHead.get_ActualWidth(), this.imgHead.get_ActualHeight());
			if (this.mContact == null)
			{
				return null;
			}
			BitmapImage bitmapImage = HeadImgMgr.getHeadImage(this.mContact);
			if (bitmapImage == HeadImgMgr.defaultHeadImage)
			{
				bitmapImage = (this.imgHead.imgHead.get_Source() as BitmapImage);
			}
			base.GoToPage("/Source/UI/Contact/HighQualityHeadImgView.xaml", new object[]
			{
				bitmapImage,
				this.mContact.strUsrName,
				rect
			}, false);
			return null;
		}
		private void btnFollow_Click(object sender, RoutedEventArgs e)
		{
			this.getCover(null);
			ServiceCenter.sceneVerifyUser.doSceneAddContact(this.mContact.strUsrName, (AddContactScene)this.mContact.nAddContactScene);
		}
		private void btnSeeMsg_Click(object sender, RoutedEventArgs e)
		{
			ChatContainerPage.GoToChatPage(this, this.mContact.strUsrName, null, null, null);
		}
		private void toogleReceiveMsgStateChanged(object sender, bool isCheckOn)
		{
			ContactMgr.SetReceiveMsg(this.mContact, isCheckOn);
			ServiceCenter.sceneNewSync.doScene(4, syncScene.MM_NEWSYNC_SCENE_OTHER);
		}
		private void toogleShowInProfileStateChanged(object sender, bool isCheckOn)
		{
			ContactMgr.SetShowInMyProfile(this.mContact, isCheckOn);
			ServiceCenter.sceneNewSync.doScene(4, syncScene.MM_NEWSYNC_SCENE_OTHER);
		}
		private void initToggles()
		{
			if (this.mBIsTogglesInited)
			{
				return;
			}
			this.mBIsTogglesInited = true;
			this.toggleReceive.txtTitle.set_FontSize(24.0);
			this.toggleReceive.Text = strings.EnterpriseContactInfo_recieveMsg;
			this.toggleReceive.onToggleStateChanged = new OnToggleStateChanged(this.toogleReceiveMsgStateChanged);
			this.toggleShowInMyList.txtTitle.set_FontSize(24.0);
			this.toggleShowInMyList.Text = strings.EnterpriseContactInfo_showInMyProfile;
			this.toggleShowInMyList.onToggleStateChanged = new OnToggleStateChanged(this.toogleShowInProfileStateChanged);
		}
		private void initUI()
		{
			this.svRoot.set_Visibility(0);
			if (this.mContact == null)
			{
				return;
			}
			this.imgHead.ItemObject = this.mContact;
			this.txtNicks.Text = this.mContact.strNickName;
			this.refreshVerifiedStatus();
			this.SetSignature(this.mContact.strSignature);
			int arg_5E_0 = this.mContact.nSex;
			this.refreshFllowedStatus();
		}
		private void refreshFllowedStatus()
		{
			if (ContactMgr.isContact(this.mContact))
			{
				this.toFriendMode();
				return;
			}
			this.toNotFriendMode();
		}
		private void refreshVerifiedStatus()
		{
			if (this.mContact == null)
			{
				return;
			}
			ProfileInfoData verifyInfo = ProfileDataMgr.GetVerifyInfo(this.mContact.strVerifyInfo);
			if (verifyInfo == null)
			{
				this.ctrlVerify.set_Visibility(1);
				return;
			}
			this.ctrlVerify.set_Visibility(0);
			if (ContactHelper.IsVerifiedContactVerified(this.mContact))
			{
				this.ctrlVerify.txtAreaTitle.set_Text(strings.COM_VerifyTag);
				if (this.ctrlVerify.panelTitle.get_Children().get_Count() != 2)
				{
					Image image = new Image();
					image.set_Margin(new Thickness(10.0, 0.0, 0.0, 0.0));
					image.set_Source(ToolFunction.GetImgFromContentSource("/Resource/Img/ContactList/VerifyTag.png"));
					this.ctrlVerify.panelTitle.get_Children().Add(image);
					this.ctrlVerify.txtStaticText.set_FontSize(30.0);
				}
				this.ctrlVerify.panelTitle.get_Children().get_Item(1).set_Visibility(0);
			}
			else
			{
				if (this.ctrlVerify.panelTitle.get_Children().get_Count() == 2)
				{
					this.ctrlVerify.panelTitle.get_Children().get_Item(1).set_Visibility(1);
				}
				verifyInfo.mStrTitle = strings.Setting_Account_V_NotVerified;
				this.txtID.set_Text(strings.Contacts_NoAuthenticate);
			}
			this.ctrlVerify.InfoData = verifyInfo;
		}
		public void SetSignature(string strSig)
		{
			if (string.IsNullOrEmpty(strSig))
			{
				this.txtSig.set_Visibility(1);
				return;
			}
			this.txtSig.set_Visibility(0);
			this.txtSig.Text = strSig;
		}
		private void toFriendMode()
		{
			this.btnFollow.set_Visibility(1);
			this.panelFollowed.set_Visibility(0);
			this.ctrlBrandLinks.ItemObject = this.mContact;
			if (ContactMgr.IsReceiveMsg(this.mContact))
			{
				this.toggleReceive.IsChecked = true;
			}
			else
			{
				this.toggleReceive.IsChecked = false;
			}
			if (ContactMgr.IsShowInMyProfile(this.mContact))
			{
				this.toggleShowInMyList.IsChecked = true;
			}
			else
			{
				this.toggleShowInMyList.IsChecked = false;
			}
			this.disTencentWeibo();
			this.setAppBar();
			this.initToggles();
		}
		private void toNotFriendMode()
		{
			this.btnFollow.set_Visibility(0);
			this.panelFollowed.set_Visibility(1);
			this.ctrlBrandLinks.ItemObject = null;
			base.set_ApplicationBar(null);
		}
		private void releaseCover()
		{
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
		}
		private void getCover(string strToShow = null)
		{
			ProcessingCover.getProgressBar(this.LayoutRoot, strToShow, null, false, false, null);
		}
		private void disTencentWeibo()
		{
			Contact contact = this.mContact;
			if (contact != null && ContactMgr.isTWeiboShown(contact) && this.ctrlTWeibo == null)
			{
				this.ctrlTWeibo = ProfileClickContentGridCtrl.GetOneItem();
				this.ctrlTWeibo.set_Margin(new Thickness(0.0, 10.0, 0.0, 0.0));
				this.panelFollowed.get_Children().Insert(0, this.ctrlTWeibo);
				this.ctrlTWeibo.InfoData = ProfileDataMgr.GetTencentWeiboInfo(null, contact.strWeiboNickname, contact.strWeibo);
			}
		}
		private ApplicationBar setAppBar()
		{
			if (this.mBar != null)
			{
				if (!this.mBar.get_IsVisible())
				{
					this.mBar.set_IsVisible(true);
				}
				return this.mBar;
			}
			this.mBar = new ApplicationBar();
			this.mBar.set_IsMenuEnabled(true);
			this.mBar.set_IsVisible(true);
			ApplicationBarMenuItem applicationBarMenuItem = new ApplicationBarMenuItem(strings.Contacts_Confirm_Title);
			applicationBarMenuItem.add_Click(new EventHandler(this.btnRecomend_Click));
			this.mBar.get_MenuItems().Add(applicationBarMenuItem);
			ApplicationBarMenuItem applicationBarMenuItem2 = new ApplicationBarMenuItem(strings.COM_Del);
			applicationBarMenuItem2.add_Click(new EventHandler(this.btnMenu_Click));
			this.mBar.get_MenuItems().Add(applicationBarMenuItem2);
			base.set_ApplicationBar(this.mBar);
			this.setAppBarStyle(base.get_ApplicationBar());
			return this.mBar;
		}
		private void btnRecomend_Click(object sender, EventArgs e)
		{
			ForwardMsgHelper.ToForwardMsg(this.mContact, ForwardKind.Kind_ShareCard, null);
		}
		private void btnMenu_Click(object sender, EventArgs e)
		{
			MMMessageBox mMMessageBox = MMMessageBox.Show(strings.EnterpriseContactInfo_cancelFollow, string.Format(strings.EnterpriseContactInfo_cancelWarning, this.mContact.strNickName), true, strings.Con_Detail_MsgDelBtnLeft, strings.COM_Cancel);
			mMMessageBox.ReturnEvent = new DlgReturnEvent(this.OnDeleteContactHandler);
		}
		private void OnDeleteContactHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				ContactHelper.DeleteContact(this.mContact, true);
				base.GoBack();
				break;
			case 1:
				break;
			default:
				return;
			}
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
		}
		public static void GotoThisPage(string strUserName, bool bIsRemoveCurrentPage = false)
		{
			if (string.IsNullOrEmpty(strUserName))
			{
				return;
			}
			Contact contact = StorageMgr.contact.method_0(strUserName);
			if (contact == null)
			{
				contact = new Contact
				{
					strUsrName = strUserName
				};
			}
			ToolFunction.GotoPageForUserControl("/Source/UI/Contact/VerifiedPeopleInfo.xaml", new object[]
			{
				contact
			}, bIsRemoveCurrentPage);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Contact/VerifiedPeopleInfo.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.svRoot = (ScrollViewer)base.FindName("svRoot");
			this.panelProfile = (StackPanel)base.FindName("panelProfile");
			this.panelTop = (StackPanel)base.FindName("panelTop");
			this.imgHead = (BrandHeadCtrl)base.FindName("imgHead");
			this.txtNicks = (ScrollTextBlock)base.FindName("txtNicks");
			this.txtID = (TextBlock)base.FindName("txtID");
			this.imgVerifyTag = (Image)base.FindName("imgVerifyTag");
			this.txtVerifyTag = (TextBlock)base.FindName("txtVerifyTag");
			this.txtSig = (EmojiTextEx)base.FindName("txtSig");
			this.panelContentInfo = (StackPanel)base.FindName("panelContentInfo");
			this.panelAblum = (Grid)base.FindName("panelAblum");
			this.ctrlVerify = (ProfileTxtContentCtrl)base.FindName("ctrlVerify");
			this.btnFollow = (Button)base.FindName("btnFollow");
			this.panelFollowed = (StackPanel)base.FindName("panelFollowed");
			this.ctrlBrandLinks = (BrandCustomLinksCtrl)base.FindName("ctrlBrandLinks");
			this.toggleReceive = (MMToggleSwitch)base.FindName("toggleReceive");
			this.toggleShowInMyList = (MMToggleSwitch)base.FindName("toggleShowInMyList");
			this.btnSeeMsg = (Button)base.FindName("btnSeeMsg");
		}
	}
}
